﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EntityBinder
{
	public class TransformerFactory
	{
		private static Dictionary<Type, Interface.ITransformer> m_transformers = new Dictionary<Type, Interface.ITransformer>();

		static TransformerFactory()
		{
			m_transformers.Add(typeof(bool), new Transformer.BoolTransformer());
			m_transformers.Add(typeof(char), new Transformer.CharTransformer());
			m_transformers.Add(typeof(double), new Transformer.DoubleTransformer());
			m_transformers.Add(typeof(float), new Transformer.FloatTransformer());
			m_transformers.Add(typeof(int), new Transformer.IntTransformer());
			m_transformers.Add(typeof(long), new Transformer.LongTransformer());
			m_transformers.Add(typeof(string), new Transformer.StringTransformer());
		}

		public static void AddSupportedTransformer(Type _forType, Interface.ITransformer _transformerInstance)
		{
			if(m_transformers.ContainsKey(_forType))
			{
				m_transformers.Remove(_forType);
			}

			m_transformers.Add(_forType, _transformerInstance);
		}

		public static Interface.ITransformer Get(Type _forType)
		{
			if(m_transformers.ContainsKey(_forType))
			{
				return m_transformers[_forType];
			}
			throw new EntityBinderException("TransformerFactory", "Get", "Do not have any transformer for type " + _forType);
		}

		public static bool Has(Type _forType)
		{
			return m_transformers.ContainsKey(_forType);
		}
	}
}
